<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="../common/common.jsp"%>
<link rel="stylesheet" href="${ctx}/page/member/css/register.css" />
<title>找回密码</title>
</head>
<body>
	<div class="wrapper">
		<%@ include file="../common/header.jsp"%>
		<div class="container">
			<div class="row">
		        <div class="col-md-offset-3 col-md-6 center-vertical">
		            <form class="form-horizontal">
		                <span class="heading">找回密码</span>
		                 <div class="form-group">
							<div class="input-group">
		                    	<input type="text" class="form-control" id="email" name="email" placeholder="邮箱">
		                    	<i class="fa fa-user"></i>
						      	<span class="input-group-btn">
						        	<button class="btn btn-info codeBtn" type="button" onclick="sendEmail()">发送验证码</button>
						      	</span>
						    </div>
					    </div>
		                <div class="form-group">
		                    <input type="text" class="form-control" id="code" name="code" placeholder="验证码">
		                    <i class="fa fa-user"></i>
		                </div>
		                <div class="form-group">
		                    <input type="password" class="form-control" id="password" name="password" placeholder="新密码">
		                    <i class="fa fa-user"></i>
		                </div>
		                <div class="form-group">
		                  	<span id="error_message"></span>
		                  	<p></p>
		                    <button type="button" class="btn btn-info registerBtn" onclick="resetPassword()">重置密码</button>
		                </div>
		            </form>
		        </div>
			</div>
		</div>
		<%@ include file="../common/footer.jsp"%>
	</div>
	<script type="text/javascript">
		function resetPassword(){
			var errorMsg = $("#error_message");
			var email = $("#email").val();
			var code = $("#code").val();
			var password = $("#password").val();
			if (email.length == 0) {
				errorMsg.html("邮箱不能为空");
				return;
			}
			if (code.length == 0) {
				errorMsg.html("验证码不能为空");
				return;
			}
			if (password.length == 0) {
				errorMsg.html("密码不能为空");
				return;
			}
			if (password.length < 6) {
				errorMsg.html("密码长度不能小于6个字符");
				return;
			}
			if(password.length > 11){
				errorMsg.html("密码长度不能大于11个字符");
				return;
			}
			$.ajax({
				type : 'POST',
				url : ctx + '/member/resetPassword.do',
				data : {
					email : email,
					code : code,
					password : password
				},
				dataType : 'json',
				timeout : 30000,
				context : $('body'),
				success : function(data) {
					if (data.code == "ok") {
						showTip2('密码重置成功!');
						history.back();
					} else {
						showTip2(data.msg);
					}
				},
				error : function(xhr, type) {
					showTip2('提交失败!');
				}
			});
		}
	</script>
</body>
</html>